fix(stripe): accept any matching webhook v1 signature#480
fix(stripe): accept any matching webhook v1 signature#480jsdavid278-cyber wants to merge 3 commits into
Conversation
Greptile SummaryThis PR fixes webhook signature verification to correctly handle Stripe's secret rotation scenario, where multiple
Confidence Score: 5/5Safe to merge — the change is a targeted, well-tested fix to header parsing with no regressions introduced. The new parsing loop is strictly more correct than the replaced Object.fromEntries call: it preserves all v1 values, still uses timingSafeEqual for each comparison, and throws on the same error conditions as before. The test covers both orderings of valid/invalid signatures. No existing behavior is removed or weakened. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Incoming Webhook Request] --> B[Parse Stripe-Signature header]
B --> C{Split on comma,\ncollect all t= and v1= parts}
C --> D{timestamp present\nand signatures.length > 0?}
D -- No --> E[Throw: missing t or v1]
D -- Yes --> F[Compute expected HMAC\nsha256 over timestamp.rawBody]
F --> G[Loop over signatures]
G --> H{actualBuffer.length ==\nexpectedBuffer.length\nAND timingSafeEqual?}
H -- Yes --> I[Return — webhook accepted]
H -- No --> J{More signatures?}
J -- Yes --> G
J -- No --> K[Throw: Invalid signature]
Reviews (2): Last reviewed commit: "test(stripe): cover matching signature l..." | Re-trigger Greptile |
Summary
Why
Stripe can include multiple v1 signatures during webhook secret rotation. The previous Object.fromEntries parsing only kept the last v1 value, so a valid signature could be ignored if another v1 appeared later.
Testing
uGig gig: abd6b2a0-e728-48cf-a46f-f99e419ed94e